package com.lzw.bluetoothpractice.Activitys;

import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lzw.bluetoothpractice.Adapters.RecommendHosptialListAdapter;
import com.lzw.bluetoothpractice.Adapters.UserReadMessageListAdapter;
import com.lzw.bluetoothpractice.AppConfig;
import com.lzw.bluetoothpractice.Models.SendMessage;
import com.lzw.bluetoothpractice.Models._User;
import com.lzw.bluetoothpractice.R;
import com.lzw.bluetoothpractice.Utils.AppUtil;
import com.lzw.bluetoothpractice.Utils.SharePreferenceUtils;
import com.lzw.bluetoothpractice.bean.RecommendHosptialBean;
import com.lzw.bluetoothpractice.bean.SystemUserBean;
import com.lzw.bluetoothpractice.bean.SystemUserListBean;
import com.lzw.bluetoothpractice.network.HeadAssmblyUtils;
import com.lzw.bluetoothpractice.network.RetrofitManager;
import com.lzw.bluetoothpractice.network.api.RequestApi;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static com.lzw.bluetoothpractice.MyApplication.getContext;

public class MyDoctorsActivity extends BaseActivity {

    private Map<String, String> keyMap;
    RecyclerView rcDoctorMsgList;
    UserReadMessageListAdapter userReadMessageListAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_doctors);
        rcDoctorMsgList=fd(R.id.rcDoctorMsgList);

        InitView();
        initMyDoctor();
    }

    private  void InitView(){
        InitNavBar2(true,"我的医生",true);




    }

    private void initMyDoctor(){
        try {
            keyMap = HeadAssmblyUtils.HeadAssembly("/dev-api/android/doctor/list");
        } catch (Exception e) {
            e.printStackTrace();
        }
        String accessToken = SharePreferenceUtils.getString(getContext(),"access_token",null);;
        String userid = SharePreferenceUtils.getString(getContext(),"userId",null);
        RetrofitManager.getInstance(AppConfig.BASE_URL)
                .createReq(RequestApi.class).getMyDoctor(Long.parseLong(userid),"1", AppUtil.getVersionCode() + "", accessToken ,keyMap.get("gmtStr"), keyMap.get("contentMD5"), keyMap.get("hmacCode")).
                observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Subscriber<JSONObject>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

                Log.e("我的医生：",e.getMessage()+"");

            }

            @Override
            public void onNext(JSONObject json) {

                SystemUserListBean systemUserBean = JSON.parseObject(json.toString(), SystemUserListBean.class);
                if(systemUserBean.getCode()==200){

                    //Article article=new Article();
                    LinearLayoutManager linearLayoutManager2=new LinearLayoutManager(MyDoctorsActivity.this);
                    linearLayoutManager2.setOrientation(LinearLayoutManager.VERTICAL);
                    rcDoctorMsgList.setLayoutManager(linearLayoutManager2);
                    userReadMessageListAdapter=new UserReadMessageListAdapter(getContext());
                    userReadMessageListAdapter.updateData(systemUserBean.getData());
                    rcDoctorMsgList.setAdapter(userReadMessageListAdapter);


                }else {
                    Toast toast=Toast.makeText(MyDoctorsActivity.this,"查询我的医生失败",Toast.LENGTH_LONG);
                    toast.show();
                }


            }
        });

    }
}
